//
//  GJFEditPersonTableViewCell.m
//  Wedding
//
//  Created by 郭静芬 on 2017/1/11.
//  Copyright © 2017年 郭静芬. All rights reserved.
//

#import "GJFEditPersonTableViewCell.h"

@interface  GJFEditPersonTableViewCell ()
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UIImageView *avatar;
@property (nonatomic, strong) UITextField *textFiled;
@end

@implementation GJFEditPersonTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView).mas_offset(15 * XX);
            make.top.bottom.mas_equalTo(self.contentView).mas_offset(0);
            make.width.mas_equalTo(WIDTH / 3);
        }];
        [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-5 * XX);
            make.top.mas_equalTo(self.contentView).mas_offset(10 * YY);
            make.bottom.mas_equalTo(self.contentView).mas_offset(-10 * YY);
            make.width.mas_equalTo(60);
        }];
        [self.textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-5 * XX);
            make.top.mas_equalTo(self.contentView).mas_offset(5 * YY);
            make.bottom.mas_equalTo(self.contentView).mas_offset(-5 * YY);
            make.left.mas_equalTo(self.title.mas_right).mas_offset(0);
        }];
    }
    return self;
}

- (void)setModel:(GJFEditPersonModel *)model {
    _model = model;
    self.title.text = model.key;
    if ([model.key isEqualToString:@"编辑头像"]) {
        self.avatar.hidden = NO;
        self.textFiled.hidden = YES;
        [self.avatar sd_setImageWithURL:[NSURL URLWithString:model.value] placeholderImage:[UIImage imageNamed:@"编辑头像"]];
        
    }
    else {
        self.avatar.hidden = YES;
        self.textFiled.hidden = NO;
        self.textFiled.text = model.value;
        self.textFiled.placeholder = model.placeholder;
    }
    if ([model.key isEqualToString:@"手机号"]) {
        self.accessoryType = UITableViewCellAccessoryNone;
        [self.textFiled mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-15 * XX);
        }];
    }
    else {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [self.textFiled mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-5 * XX);
        }];
    }
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        [self.contentView addSubview:_title];
    }
    return _title;
}

- (UIImageView *)avatar {
    if (!_avatar) {
        _avatar = [[UIImageView alloc] init];
        _avatar.layer.cornerRadius = 30 * XX;
        _avatar.clipsToBounds = YES;
        [self.contentView addSubview:_avatar];
    }
    return _avatar;
}

- (UITextField *)textFiled {
    if (!_textFiled) {
        _textFiled = [[UITextField alloc] init];
        _textFiled.textAlignment = NSTextAlignmentRight;
        _textFiled.enabled = NO;
        [self.contentView addSubview:_textFiled];
    }
    return _textFiled;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
